package com.lianniu.mgr.cms.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.lianniu.mgr.base.BaseResult;
import com.lianniu.mgr.cms.model.PopChannelVo;
import com.lianniu.mgr.cms.service.IPopChannelServie;
import com.lianniu.mgr.pagination.PaginationInfo;

@Controller
@RequestMapping("/rest/PopChannel")
public class PopChannelRestController {

private final static Logger logger = Logger.getLogger(PopChannelRestController.class);
	
	@Autowired
	private IPopChannelServie popChannelServie;
	
	@RequestMapping(value="/PopPopChannelList",method={RequestMethod.GET,RequestMethod.POST})
	public @ResponseBody BaseResult PopPopChannelList(HttpServletRequest request, PopChannelVo curVo, PaginationInfo paginationInfo)
	 {
	       logger.info("PopChannelRestController  PopPopChannelList begin.");
	       try {
	           
	           logger.info("PopChannelList begin.");          
	           BaseResult baseResult = popChannelServie.selectByPopChannelForPage(curVo, paginationInfo);
	           logger.info("PopChannelList end.");
	           logger.info("PopChannelRestController PopChannelList end.");
	           return baseResult;
	       } catch (Exception e) {
	       logger.error("PopChannelRestController PopChannelList error:" + e.getMessage());
	       logger.error("PopChannelRestController PopChannelList end.");
	       return BaseResult.exception(e.getMessage());
	     }
	  }
	
	@RequestMapping(value = {"/PopChannelAdd"}, method = RequestMethod.POST)
	public @ResponseBody BaseResult PopChannelAdd(HttpServletRequest request,PopChannelVo curVo) {
	      logger.info("PopChannelRestController PopChannelAdd begin.");      
	      logger.info("PopChannelRestController PopChannelAdd:"+ JSON.toJSONString(curVo));
	      try {
	          logger.info("PopChannelAdd begin.");
	        
	          BaseResult baseResult = popChannelServie.insertPopChannel(curVo);
	          logger.info("PopChannelAdd baseResult:" + JSON.toJSONString(baseResult));
	          logger.info("PopChannelAdd end.");
	          return baseResult;

	    } catch (Exception e) {
	      logger.error("ProductBrandAdd error:"+e.getMessage());
	      logger.info("PopChannelRestController ChannelAdd end.");
	      return BaseResult.exception(e.getMessage());
	    }

	  }
	
	 
	@RequestMapping(value = {"/PopChannelEdit"}, method = RequestMethod.POST)
	  public @ResponseBody BaseResult PopChannelEdit(HttpServletRequest request,PopChannelVo curVo) {
	      logger.info("PopChannelRestController PopChannelEdit begin.");      
	      logger.info("PopChannelRestController PopChannelEdit:"+ JSON.toJSONString(curVo));
	      try {
	          logger.info("PopChannelEdit begin.");
	          BaseResult baseResult = popChannelServie.updateById(curVo);
	          logger.info("PopChannelEdit baseResult:" + JSON.toJSONString(baseResult));
	          logger.info("PopChannelEdit end.");
	          return baseResult;

	    } catch (Exception e) {
	      logger.error("PopChannelRestController error:"+e.getMessage());
	      logger.info("PopChannelRestController PopChannelEdit end.");
	      return BaseResult.exception(e.getMessage());
	    }
	  }
	  
	
	 @RequestMapping(value="/selectPopChannelById",method={RequestMethod.GET,RequestMethod.POST})
	  public @ResponseBody BaseResult selectPopChannelById(HttpServletRequest request,PopChannelVo curVo) {
	        logger.info("PopChannelRestController selectPopChannelById begin.");
	        try {
	                    
	          BaseResult baseResult = popChannelServie.selectById(curVo);
	          logger.info("PopChannelRestController end.");
	          logger.info("PopChannelRestController selectPopChannelById end.");
	          return baseResult;
	        } catch (Exception e) {
	          logger.error("PopChannelRestController selectPopChannelById error:" + e.getMessage());
	          logger.error("PopChannelRestController selectPopChannelById end.");
	          return BaseResult.exception(e.getMessage());
	        }
	  } 
	 
	 @RequestMapping(value = {"/PopChannelDel"}, method = RequestMethod.POST)
	  public @ResponseBody BaseResult PopChannelDel(HttpServletRequest request) {
	      logger.info("PopChannelRestController PopChannelDel begin.");
	     try {          
	          logger.info("PopChannelDel begin.");
	          BaseResult baseResult = popChannelServie.deletePopChannelBatch(request.getParameter("ids").split(","));		
	          logger.info("PopChannelDel baseResult:" + JSON.toJSONString(baseResult));
	          logger.info("PopChannelDel end.");
	          
	          logger.info("PopChannelRestController PopChannelDel end.");
	          return baseResult;

	    } catch (Exception e) {
	      logger.error("PopChannelRestController PopChannelDel error:" + e.getMessage());
	      logger.info("PopChannelRestController PopChannelDel end.");
	      return BaseResult.exception(e.getMessage());
	    }

	  }
	
}
